package edu.bit.water.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import edu.bit.water.entity.EntityEvaEntPrdInfo;
import edu.bit.water.service.EntityEvaEntPrdInfoService;

/**
 * 用于处理生产实际情况的控制层
 * @author HJS
 *
 */
@Controller
@RequestMapping("/entity_eva_ent_prd_info")
public class EntityEvaEntPrdInfoController extends BaseController{

	@Autowired
	private EntityEvaEntPrdInfoService entityEvaEntPrdInfoService;
	
	/**
	 * @param  生产情况实体
	 * @return 成功返回1,失败返回0	 
	 */
	@RequestMapping("/insert")
	@ResponseBody
	public Map<String, Object> insert(EntityEvaEntPrdInfo entityEvaEntPrdInfo) {
		Map<String, Object> modelMap = new HashMap<>();
		if(currentUser()==null) {
			modelMap.put("status", "failed");
			return modelMap;
		}
		int userid=currentUser().getId();
		//String username=currentUser().getName();
		entityEvaEntPrdInfo.setUserId(userid);
		//labelWaterBala.setUserName(username);

		int n = entityEvaEntPrdInfoService.insert(entityEvaEntPrdInfo);
		if(n == 1) {
	    	modelMap.put("status", "success");
	    }
	    else
	    	modelMap.put("status", "failed");
		return modelMap;
	}
	/**
	 * @param  id 要删除记录的主键
	 * @return 成功返回1,失败返回0	 
	 */
	@RequestMapping("/delete")
	@ResponseBody
	public Map<String, Object> delete(@RequestBody List<Integer> ids) {
		Map<String, Object> modelMap = new HashMap<>();
		int n = entityEvaEntPrdInfoService.deleteId(ids);
		if(n == 1) {
	    	modelMap.put("status", "success");
	    }
	    else
	    	modelMap.put("status", "failed");
		return modelMap;
	}
	/**
	 * 更新生产情况实体
	 * @param entityEvaEntPrdInfo 生产情况实体
	 * @return 成功返回1,失败返回0
	 */
	@RequestMapping("/update")
	@ResponseBody
	public Map<String, Object> update(EntityEvaEntPrdInfo entityEvaEntPrdInfo) {
		Map<String, Object> modelMap = new HashMap<>();
		int n = entityEvaEntPrdInfoService.update(entityEvaEntPrdInfo);
		if(n == 1) {
	    	modelMap.put("status", "success");
	    }
	    else
	    	modelMap.put("status", "failed");
		return modelMap;
	}
	/**
	 * 查询生产情况实体
	 * @param id 外键
	 * @return 成功返回记录,没有返回null
	 */
	@RequestMapping("/select")
	@ResponseBody
	public Map<String, Object> select(int label_id){
		Map<String, Object> modelMap = new HashMap<>();
		List<EntityEvaEntPrdInfo> list = entityEvaEntPrdInfoService.select(label_id);
		modelMap.put("rows", list);
		return modelMap;
	}
}
